package com.bear.fastrepair.mvvm.ui.employee.dialog

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import com.bear.fastrepair.base.BaseDialog
import com.bear.fastrepair.databinding.DialogBillAddBinding
import com.bear.fastrepair.entity.BillInfoAdd
import com.blankj.utilcode.util.ToastUtils

class BillCommitDialog(context: Context, private val block: (BillInfoAdd) -> Unit) :
    BaseDialog(context) {

    private lateinit var binding: DialogBillAddBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DialogBillAddBinding.inflate(LayoutInflater.from(context))
        setContentView(binding.root)
        setCancelable(true)
        binding.confirm.setOnClickListener {
            val price = binding.price.text.toString()
            val remarks = binding.remarks.text.toString()
            when {
                price.isEmpty() -> {
                    ToastUtils.showLong("请填写金额！")
                    return@setOnClickListener
                }
                remarks.isEmpty() -> {
                    ToastUtils.showLong("请填写备注")
                    return@setOnClickListener
                }
                else -> {
                    val billInfoAdd = BillInfoAdd(
                        billType = if (binding.cost.isChecked) 0 else 1,
                        price = price.trim().toInt(),
                        remark = remarks
                    )
                    block(billInfoAdd)
                    dismiss()
                }
            }
        }
    }
}